import request from '@/utils/request'
import type{SpuImageData,SpuSaleAttrData} from './spu'
export interface SkuImageData {
  id?: number,
  skuId?: number,
  imgName: string,
  imgUrl: string,
  spuImgId: number,
  isDefault: string
}

export interface SkuAttrValueData {
  id?: number,
  attrId: number | string,
  valueId:number | string,
  skuId?: number,
  attrName?: string,
  valueName?: string,
}

export interface SkuSaleAttrValueData {
  id?: number,
  skuId?: number,
  spuId?: number,
  saleAttrValueId: number | string,
  saleAttrId: number | string,
  saleAttrName?: string,
  saleAttrValueName?: string
}

export interface SkuData {
  id?: number,
  spuId: number,
  price: number,
  skuName: string,
  skuDesc: string,
  weight: string,
  tmId: number,
  category3Id: number,
  skuDefaultImg: string,
  isSale?: number,
  createTime?: string,
  skuImageList: SkuImageData[],
  skuAttrValueList: SkuAttrValueData[],
  skuSaleAttrValueList: SkuSaleAttrValueData[]
}

type SkuPageListData = {
  records: SkuData[],
  total: number,
  size: number,
  current: number,
  searchCount: boolean,
  pages: number
}




export default {
  /**
   * @description 下架商品
   * @url http://39.98.123.211:8510/admin/product/cancelSale/{skuId}
   * @param skuId 
   * @returns Promise<null>
   */
  cancelSale(skuId:number){
    return request.get<any,null>(`/admin/product/cancelSale/${skuId}`)
  },


  /**
   * @description 上架商品
   * @url http://39.98.123.211:8510/admin/product/onSale/{skuId}
   * @param skuId 
   * @returns Promise<null>
   */
  onSale(skuId:number){
    return request.get<any,null>(`/admin/product/onSale/${skuId}`)
  },


  /**
   * @description 删除sku
   * @url http://39.98.123.211:8510/admin/product/deleteSku/{skuId}
   * @param skuId 
   * @returns Promise<null>
   */
  deleteSku(skuId:number){
    return request.delete<any,null>(`/admin/product/deleteSku/${skuId}`)
  }, 

 
  /**
   * @description 根据spu的id去查找这个spu内部所有sku列表
   * @url http://39.98.123.211:8510/admin/product/findBySpuId/{spuId}
   * @param spuId 
   * @returns Promise<SkuData[]>
   */
  findBySpuId(spuId:number){
    return request.get<any,SkuData[]>(`/admin/product/findBySpuId/${spuId}`)
  },


  /**
   * @description 根据sku的id获取sku详情信息
   * @url http://39.98.123.211:8510/admin/product/getSkuById/{skuId}
   * @param skuId 
   * @returns Promise<SkuData>
   */
  getById(skuId:number){
    return request.get<any,SkuData>(`/admin/product/getSkuById/${skuId}`)
  },


  /**
   * @description 获取sku的分页列表
   * @url http://39.98.123.211:8510/admin/product/list/{page}/{limit}
   * @param page 当前页面
   * @param limit 每页展示数量
   * @returns Promise<SkuPageListData>
   */
  getPageList(page:number,limit:number){
    return request.get<any,SkuPageListData>(`/admin/product/list/${page}/${limit}`)
  },

  
  /**
   * @description 存储Sku信息
   * @url http://39.98.123.211:8510/admin/product/saveSkuInfo
   * @param sku 
   * @returns Promise<null>
   */
  saveSkuInfo(sku:SkuData){
    return request.post<any,null>('/admin/product/saveSkuInfo',sku)
  },


  /**
   * @description 根据spu的id获取当前spu的图片列表
   * @url http://39.98.123.211:8510/admin/product/spuImageList/{spuId}
   * @param spuId 
   * @returns Promise<SpuImageData[]>
   */
  getSpuImageList(spuId:number){
    return request.get<any,SpuImageData[]>(`/admin/product/spuImageList/${spuId}`)
  },


  /**
   * @description 根据spu的id获取spu自己的销售属性列表
   * @url http://39.98.123.211:8510/admin/product/spuSaleAttrList/{spuId}
   * @param spuId 
   * @returns Promise<SpuSaleAttrData[]>
   */
  getSpuSaleAttrList(spuId:number){
    return request.get<any,SpuSaleAttrData[]>(`/admin/product/spuSaleAttrList/${spuId}`)
  } 


  // 正在开发中
  // POST /admin/product/updateSkuInfo  

  // 下面两个根据关键字找sku的详情信息单个和多个，目前不用
  // GET /admin/product/inner/findSkuInfoByKeyword/{keyword}
  // findSkuInfoByKeyword
  // POST /admin/product/inner/findSkuInfoBySkuIdList
  // findSkuInfoBySkuIdList
}